import Vue from 'vue'
import Router from 'vue-router'
import routes from './route.config'
Vue.use(Router)

const router = new Router({
  base: process.env.BASE_URL,
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      if (from.meta.keepAlive) {
        from.meta.savedPosition = document.body.scrollTop;
      }
      return {
        x: 0,
        y: to.meta.savedPosition || 0
      }
    }
  },
  routes: [
    {
      path: '/',
      name: '飞廉Wind',
      component: () => import(/* webpackChunkName: "views" */ './views/Home.vue')
    }, {
      path: '/wechat',
      name: '微信登录',
      component: () => import(/* webpackChunkName: "views" */ './components/Wechat.vue')
    }, {
      path: '/vip',
      name: '授权',
      component: () => import(/* webpackChunkName: "views" */ './views/Vip.vue')
    }, {
      path: '/team',
      name: '团队',
      component: () => import(/* webpackChunkName: "views" */ './views/Team.vue')
    }, {
      path: '/license',
      name: '企业查询',
      component: () => import(/* webpackChunkName: "views" */ './views/License.vue')
    }, {
      path: '/pay',
      name: '支付',
      component: () => import(/* webpackChunkName: "views" */ './views/Pay.vue')
    }, {
      path: '/payList',
      name: '支付列表',
      component: () => import(/* webpackChunkName: "views" */ './views/PayList.vue')
    }, {
      path: '/sqs',
      name: '授权书',
      component: () => import(/* webpackChunkName: "views" */ './views/Sqs.vue')
    }, {
      path: '/fp',
      name: '发票管理',
      component: () => import(/* webpackChunkName: "views" */ './views/Fp.vue')
    }, {
      path: '/suporrt',
      name: '赞助',
      component: () => import(/* webpackChunkName: "views" */ './views/Suporrt.vue')
    }, ...routes]
})
router.afterEach((to) => {
  if (to.path === '/') {
    document.title = to.name
  } else {
    document.title = to.name + ' - 飞廉Wind';
  }

})
export default router
